<template>
  <div class="AdendDialog">
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
      <el-row>
        <el-col :span="16">
          <el-form-item label="名称" prop="name">
            <el-input v-model="ruleForm.name" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="程序键" prop="Keyword">
            <el-input v-model="ruleForm.Keyword" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="类型" prop="type">
            <el-input v-model="ruleForm.type" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="前端显示" prop="webshow">
            <el-select v-model="ruleForm.webshow" placeholder="请选择">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="ACL规则数" prop="acl">
            <el-input v-model="ruleForm.acl" placeholder="请输入"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="排序" prop="sort">
            <el-input v-model="ruleForm.sort" placeholder="请输入"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
        <el-button @click="resetForm('ruleForm')">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    props: {
      close: {
        type: Function,
        default: null
      },
      biaodan: {
        type: Function,
        default: null
      },
      changeText: {
        type: Function,
        default: null
      }
    },
    data() {
      return {
        ruleForm: {
          name: "",
          Keyword: "",
          type: "",
          webshow: "",
          acl: '',
          sort: ''
        },
        options: [{
            value: '显示',
            label: '显示'
          },
          {
            value: '隐藏',
            label: '隐藏'
          }
        ],
        rules: {
          name: [{
            required: true,
            message: "请输入名称",
            trigger: "blur",
          }, ],
          Keyword: [{
            required: true,
            message: "请输入程序键",
            trigger: "blur",
          }, ],
          type: [{
            required: true,
            message: "请输入类型",
            trigger: "blur",
          }, ],
          webshow: [{
            required: true,
            message: "请选择前端是否显示",
            trigger: "blur",
          }, ],
          acl: [{
            required: true,
            message: "请输入acl规则数",
            trigger: "blur",
          }, ],
          sort: [{
            required: true,
            message: "请输入排序号",
            trigger: "blur",
          }, ]
        }
      }
    },
    methods: {
      // 表单提交
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$server.formsubmit(this.ruleForm).then((res) => {
              this.$message({
                type: "success",
                message: "添加成功!",
              });
              this.changeText('表单模板')
              this.biaodan()
              // 关闭弹框
              this.close();
              for (let object in this.ruleForm) {
                this.ruleForm[object] = ''
              }
            });
          } else {
            return false;
          }
        });
      },
      resetForm(formName) {
        this.close();
      },
    }
  }
</script>

<style>
</style>
